package com.echat.serviceapigateway.security.common;

import com.echat.serviceapigateway.security.constant.Constants;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

/**
 * Created by chenmohan on 2018/08/30
 *
 * @description 针对前端框架LayUI单独创建的一个HttpResult类
 */
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
@AllArgsConstructor
public class LayUIResult extends HttpResult {

    private long count;

    public static <T> LayUIResult withPageInfo(PageInfo<T> pageInfo) {
        LayUIResult result = new LayUIResult(pageInfo.getTotal());
        result.setCode(HttpResult.SUCCESS_CODE);
        result.setMsg(Constants.EMPTY_STR);
        result.setData(pageInfo.getList());
        return result;
    }

    public static <T> LayUIResult layUIResult(String msg, int count, T data) {
        LayUIResult result = new LayUIResult(count);
        result.setCode(HttpResult.SUCCESS_CODE);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}
